package test.myorm.interceptor;

import test.myorm.chain.Interceptor;
import test.myorm.chain.Invocation;
import test.myorm.core.Sql;

public class LogInterceptor implements Interceptor {

	@Override
	public Object invoke(Invocation invocation) {
		Object[] args = invocation.getRealArgs();
		Sql sql = (Sql) args[0];
		String sqlType = null;
		int type = sql.getType();
		if(type==Sql.SQL_SELECT) {
			sqlType = "执行查询语句";
		} else if(type==Sql.SQL_INSERT) {
			sqlType = "执行新增语句";
		}else if(type==Sql.SQL_UPDATE) {
			sqlType = "执行修改语句";
		}else if(type==Sql.SQL_DELETE) {
			sqlType = "执行新增语句";
		}
		System.out.println(sqlType + "===>" + sql.getSql());
		System.out.println("参数===>" + sql.getParameter().getParamList());
		return invocation.invoke();
	}

}
